#include "stdint.h"

#include "codeQ.h"

void QueueInit(QueueTypedef* pQ)
{
	pQ->pBase = (int*)malloc(sizeof(int) * 6);
	pQ->front = 0;
	pQ->rear = 0;
}

int full_queue(QueueTypedef* pQ)
{
	if ((pQ->rear + 1) % 6 == pQ->front)
	{
		return true;
	}
	else
	{
		return false;
    }
}

int empty_queue(QueueTypedef* pQ)
{
	if (pQ->front == pQ->rear)
	{
		return true;
	}
	else
	{
		return false;
	}
}

int EnQueue(QueueTypedef* pQ, int val)
{
	if (full_queue)
	{
		return false;
	}
	else
	{
		pQ->pBase[pQ->rear] = val;
		pQ->rear = (pQ->rear + 1) % 6;
		return true;
	}
}

void TraverseQueue(QueueTypedef* pQ)
{
	int i = pQ->front;

	while (i != pQ->rear)
	{
		printf("%d ", pQ->pBase[i]);
		i = (i + 1) % 6;
	}
	printf("\n");
	return;
}

int out_queue(QueueTypedef* pQ, int* pVal)
{
	if (empty_queue(pQ))
	{
		return false;
	}
	else
	{
		*pVal = pQ->pBase[pQ->front];
		pQ->front = (pQ->front + 1) % 6;
		return true;
	}
}